package com.zmn.plat.dubbo.impl.push;

import java.util.Objects;

import javax.annotation.Resource;

import org.apache.dubbo.config.annotation.Service;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.plat.business.interfaces.push.PushNoticeAppBService;
import com.zmn.plat.common.exception.PlatException;
import com.zmn.plat.dubbo.dto.push.PushNoticeAppDRO;
import com.zmn.plat.dubbo.interfaces.push.PushNoticeRemoteService;
import com.zmn.plat.dubbo.utils.DubboConsts;

import lombok.extern.slf4j.Slf4j;

/**
 * 描述:公告推送远程接口类
 *
 * @author wangjie
 * @since 2020/3/31
 **/
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 5000, retries = -1, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class PushNoticeRemoteServiceImpl implements PushNoticeRemoteService {

    private static final String TAG = "公告推送远程接口类";

    @Resource
    PushNoticeAppBService pushNoticeAppBussService;

    /**
     * 描述: 获取app推送公告
     *
     * @param engineerId
     *            工程师id
     * @param putType
     *            推送类型
     * @param putApp
     *            推送app
     * @return com.zmn.common.dto2.ResponseDTO<com.zmn.plat.dubbo.dto.push.PushNoticeAppDRO>
     * @author wangjie
     * @since 2020/3/31
     **/
    @Override
    @ReadOnlyConnection
    public ResponseDTO<PushNoticeAppDRO> listPushNoticeApp(Integer engineerId, Integer putType, Integer putApp) {

        if (Objects.isNull(engineerId)) {
            return ResponseDTO.fail("工程师id不能为null");
        }
        if (NumberUtil.isNullOrZero(putType)) {
            return ResponseDTO.fail("推送类型不能为null");
        }
        if (NumberUtil.isNullOrZero(putApp)) {
            return ResponseDTO.fail("推送app不能为null");
        }

        log.info("[{}],engineerId:{},putType:{},putApp:{}", TAG, engineerId, putType, putApp);

        try {
            com.zmn.plat.common.dto.push.PushNoticeAppDRO pushNoticeDro = pushNoticeAppBussService.listPushNoticeApp(engineerId, putType, putApp);
            PushNoticeAppDRO map = BeanMapper.map(pushNoticeDro, PushNoticeAppDRO.class);
            return ResponseDTO.success(map, "操作成功");
        } catch (PlatException e) {
            log.error("listPushNoticeApp error", e);
            return ResponseDTO.fail(e.getMessage());
        } catch (Exception e) {
            log.error("listPushNoticeApp error", e);
            return ResponseDTO.fail("操作成功");
        }

    }
}
